{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cf4e9935",
   "metadata": {},
   "source": [
    "------\n",
    "* 2023-11-13\n",
    "* 课程：python语言\n",
    "* week10\n",
    "------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5eb4353",
   "metadata": {},
   "source": [
    "## 1.本周内容\n",
    "### 1. 元组\n",
    "\n",
    "> 1. 概念\n",
    "> 2. 创建\n",
    "> 3. 一般方法\n",
    "\n",
    "### 2. 集合\n",
    "\n",
    "> 1. 概念\n",
    "> 2. 创建\n",
    "> 3. 一般方法\n",
    "\n",
    "### 3. 字典\n",
    "\n",
    "> 1. 概念\n",
    "> 2. 创建\n",
    "> 3. 一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "538be30d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1699873706.2920902"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "time.time()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fef9cab9",
   "metadata": {},
   "outputs": [],
   "source": [
    "my_tuple1 = 1699873706.1000001,\"小明\",18,\"冰岛\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5602559d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1699873706.1000001, '小明', 18, '冰岛')\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "print(my_tuple1)\n",
    "print(type(my_tuple1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a0171e42",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1699873706, 100001, '小明', 18, '冰岛')\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "my_tuple2 = (1699873706,100001,\"小明\",18,\"冰岛\")\n",
    "print(my_tuple2)\n",
    "print(type(my_tuple2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c61479c5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('Jessa', 30, 45.75, [89, 78])\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "# 2. 第二种创建元组的方法\n",
    "my_tuple3 = tuple(('Jessa',30,45.75,[89,78]))\n",
    "print(my_tuple3)\n",
    "print(type(my_tuple3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80f94cf3",
   "metadata": {},
   "source": [
    "## 1.2 元组的一般方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "960ae5c9",
   "metadata": {},
   "source": [
    "* 1. 关于序列数据的一般方法均适用于元组\n",
    "> 1. indexing and slicing（索引取值和切片）\n",
    "> 2. in方法查询\n",
    "> 3. len()\n",
    "> 4. for 循环遍历"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4386fbb6",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1094b463",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "45.75"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple3[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "db164e75",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(45.75, [89, 78])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple3[2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "25f1c931",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Jalex' in my_tuple3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "3e2643fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Jessa' in my_tuple3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "78dcf58d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(my_tuple3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d93494a9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jessa\n",
      "30\n",
      "45.75\n",
      "[89, 78]\n"
     ]
    }
   ],
   "source": [
    "for i in my_tuple3:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "3a2aabff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple3.count(45.75)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "9f8871ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple3.index([89,78])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "315f2978",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[15], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m my_tuple3[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mjerry\u001b[39m\u001b[38;5;124m'\u001b[39m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "my_tuple3[0] = 'jerry'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a44b37c",
   "metadata": {},
   "source": [
    "# 2. 集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "ce8e57c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "歌剧社 = {'小明','小红','李华','张三'}\n",
    "街舞社 = {'小明','小佳','小仪'}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "39baabf3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小仪', '小佳', '小明', '小红', '张三', '李华'}"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 并集: 去除重复项\n",
    "歌剧社.union(街舞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "774d4a91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小明'}"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#交集：找出重复的项\n",
    "歌剧社.intersection(街舞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "a730f8c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小红', '张三', '李华'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 差集\n",
    "歌剧社.difference(街舞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "05889797",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小仪', '小佳'}"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "街舞社.difference(歌剧社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "db26892e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小仪', '小佳', '小红', '张三', '李华'}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对称差集\n",
    "歌剧社.symmetric_difference(街舞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "cb402b33",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function symmetric_difference:\n",
      "\n",
      "symmetric_difference(...) method of builtins.set instance\n",
      "    Return the symmetric difference of two sets as a new set.\n",
      "    \n",
      "    (i.e. all elements that are in exactly one of the sets.)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(歌剧社.symmetric_difference)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77862b25",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 3.字典（dict）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3612bad3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
